(function($){
	$(window).load(function(){
		
		$('.begin').each(function(i){
			$('.begin').eq(i).mouseenter(function(){
				$('.begin').removeClass('hea_hover').eq(i).addClass('hea_hover');
				$('.hea_list').removeClass('chuxian').eq(i).addClass('chuxian');
				$('.chuxian').css('z-index','20');
			}).mouseleave(function(){
				$('.begin').removeClass('hea_hover');
				$('.hea_list').removeClass('chuxian');
			})
		});
		$('.hover').each(function(i){
			$('.hover').eq(i).mouseenter(function(){
				$('.hea_list01').css('display','none').eq(i).css('display','block').css('z-index','20');
				$('.hea_list01 div').css('display','block');
			}).mouseleave(function(){
				$('.hea_list01').css('display','none');
			})
		});
		$('.choose_city span').click(function(){
			$('.city_list').removeClass('chuxian');
		});
		$('.city_list a').each(function(i){
			$(this).click(function(){
				$('.area span').html($(this).html());
			});
		});
		$('.shop_car').mouseenter(function(){
			if($('.hover02').text()=='0'){
				$(this).addClass('hover');
			}
		}).mouseleave(function(){
			$(this).removeClass('hover');
		});
		/**************************************搜索框***********************************/
		var 
			iIndex=-1,
			sInput=$('.search_text');
		$('.search_text').focus(function(){
			$('.search_text').val('');
		}).blur(function(){
			$('.search_text').val('松茸');
			$('.search ul').css('display','none');
		}).keyup(function(e){
			var 
				e=e||event,
				aLi=$('.search ul li');
			if(e.keyCode==38||e.keyCode==40){
				if(e.keyCode==38&&iIndex>=0){
					if(iIndex==0){
						iIndex=aLi.length-1;
					}else{
						iIndex--;
					}
				}else if(e.keyCode==40&&iIndex<=aLi.length-1){
					if(iIndex==aLi.length-1){
						iIndex=0;
					}else{
						iIndex++;
					}
				}
				sInput.val(aLi.removeClass('active').eq(iIndex).addClass('active').data('key'));
			}
		}).bind('input propertychange',function(){
			$('.search ul').css('display','block');
			var sTextVal=$(this).val();
			if(sTextVal){
				$.ajax({
					url:'http://www.sfbest.com/productlist/keysearch?',
					data:{q:sTextVal},
					jsonp:'callback',
					dataType:'jsonp',
					success:function(data){
						var arr=data.split('\n2');
						var str=arr.join('');
						str=str.replace('\n','');
						arr=str.split('|');
						arr.splice(0,1);
						var name=[],num=[];
						for(var i=0;i<arr.length;i++){
							if(i%2==0){
								name.push(arr[i]);
							}else{
								num.push(arr[i]);
							}
						}
						var sHtml='';
						for(var i=0;i<name.length;i++){
							if(i!=(name.length-1)){
								sHtml+='<li data-key = "'+name[i]+'"><a href="javascript:;">'+name[i]+'<span>约'+num[i]+'件</span></a></li>';
							}else{
								sHtml+='<li class="wenzhang" data-key = "'+name[i]+'"><a href="javascript:;">搜'+name[i]+'相关文章<span>有'+num[i]+'篇</span></a></li>';
							}
							
						}
						
						$('.search ul').html(sHtml);
						iIndex=-1;
					}
				});
			}
		});
		/**************************************左菜单栏***********************************/
		var index=0;
		$('.main_nav dl').each(function(i){
			$('.main_nav dl').eq(i).mouseover(function(){
				index=i;
				$('.main_nav dl').removeClass('hover').eq(i).addClass('hover');
				$('.big_menu_bg').css('display','block');
				$('.big_menu').css('display','block');
				$('.big_menu div').css('display','none').eq(i).css('display','block');
				$('.big_menu').css('z-index','1000');
				
			}).mouseout(function(){
				$('.main_nav dl').removeClass('hover');
				$('.big_menu_bg').css('display','none');
				$('.big_menu').css('display','none');
				$('.big_menu div').css('display','none');
			});
			$('.big_menu').mouseover(function(){
				$('.main_nav dl').removeClass('hover').eq(index).addClass('hover');
				$('.big_menu_bg').css('display','block');
				$('.big_menu').css('display','block');
				$('.big_menu div').css('display','none').eq(index).css('display','block');
			}).mouseout(function(){
				$('.main_nav dl').removeClass('hover');
				$('.big_menu_bg').css('display','none');
				$('.big_menu').css('display','none');
				$('.big_menu div').css('display','none');
			});
		});
		$('.big_menu b').click(function(){
			$('.main_nav dl').removeClass('hover');
			$('.big_menu_bg').css('display','none');
			$('.big_menu').css('display','none');
			$('.big_menu div').css('display','none');
		})
		/*****************右侧菜单******************/
		$('.slide_common').each(function(i){
			var classStr='';
			$(this).mouseenter(function(){
				if(i==0){
					classStr='.right_slide .shop_car_list';
				}else{
					classStr='.right_slide .slide_history';
				}
				$(classStr).css({
					display:'block',
					opacity:0,
					left:-50
				}).stop(true).animate({
					opacity:1,
					left:-283,
					
				})
			}).mouseleave(function(){
				if(i==0){
					classStr='.right_slide .shop_car_list';
				}else{
					classStr='.right_slide .slide_history';
				}
				$(classStr).stop(true).animate({
					left:-40,
					opacity:0,
				}).css('display','none');
			});
		});
		
		$('.backTop01').click(function(){
			$('html,body').animate({
				scrollTop:0
			},1000);
		});
		
		function getCookie(name){
			var str=document.cookie;
			var arr=str.split("; ");
			for(var i=0;i<arr.length;i++){
				var address=arr[i].indexOf("=");
				var name1=arr[i].slice(0,address);
				var value=arr[i].slice(address+1,arr[i].length);
				if(name==name1){
					return value;
				}
			}
			return "";
		}	
	});
})(jQuery);












